///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_IMAGE_GLYPH_H_
#define _BUOLA_IMAGE_GLYPH_H_

#include <buola/image.h>
#include <buola/image/ctextextents.h>
#include <buola/image/canyimage.h>

namespace buola { namespace img {

///\addtogroup image
///@{

typedef int TFontIndex;
typedef unsigned int TGlyphIndex;

struct CGlyphInfo
{
    TFontIndex mFont;
    TGlyphIndex mGlyph;
    int mW,mH;
    int mX,mY;
    int mXOff,mYOff;
};

struct CGlyphShow
{
    TGlyphIndex mGlyph;
    CPoint_d mPos;
};

enum EGlyphData
{
    GLYPHDATA_NONE=0,
    GLYPHDATA_METRICS=(1<<0),
    GLYPHDATA_PATH=(1<<1),
    GLYPHDATA_IMAGE=(1<<2)
};

DECLARE_ENUM_BITOPS(EGlyphData)

struct CGlyphCacheEntry;

struct CScaledGlyph
{
    TGlyphIndex mIndex;

    CTextExtents mMetrics; //in user space
    CTextExtents mFSMetrics; //in font space
    CRect_d mBBox;    //bounding box in device space
    CPoint_i mAdvance; //in device space (rounded)

    img::CAnyImage *mImage;
    CGlyphCacheEntry *mCacheEntry;

    EGlyphData mValid;
};

struct CGlyphCacheEntry
{
    CGlyphCacheEntry(CScaledGlyph *pGlyph)
        :   mGlyph(pGlyph)
    {
        mGlyph->mCacheEntry=this;
    }

    ~CGlyphCacheEntry()
    {
        mGlyph->mCacheEntry=nullptr;
    }

    CScaledGlyph *mGlyph;
};

///@}

/*namespace img*/ } /*namespace buola*/ }

#endif
